//
//  TabBarViewController.m
//  checkApp
//
//  Created by 小浩 on 2017/6/13.
//  Copyright © 2017年 ma. All rights reserved.
//

#import "TabBarViewController.h"
#import "ActivityViewController.h"
#import "ItemsViewController.h"

@interface TabBarViewController ()<UINavigationControllerDelegate>

@end

@implementation TabBarViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tabBar.backgroundColor = color(0, 0, 200, 0.2);
    
    ItemsViewController *itemVC = [[ItemsViewController alloc] init];
    ActivityViewController *homeVC = [[ActivityViewController alloc] init];
    NSArray *viewArr = [[NSArray alloc] initWithObjects:itemVC,homeVC, nil];
    NSMutableArray *mArray = [[NSMutableArray alloc] initWithCapacity:viewArr.count];
    
    for (UIViewController *vc in viewArr) {
        UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:vc];
        
        navCon.navigationBar.barTintColor = [UIColor whiteColor];
//        [navCon.navigationBar setShadowImage:[[UIImage alloc] init]];
//        [navCon.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
        
        
        navCon.navigationBar.translucent = NO;
        navCon.delegate = self;
        [mArray addObject:navCon];
    }
    self.viewControllers = mArray;
    self.selectedIndex = 0;
    
    
    NSArray *titleArray = @[@"项目",@"活动"];
    NSArray *picArray = @[@"TabItem",@"TabActivity"];
    NSArray *highArray = @[@"TabItem_high",@"TabActivity_high"];
    for (int i=0; i<self.tabBar.items.count; i++) {
        UITabBarItem *item = [self.tabBar.items objectAtIndex:i];
        item.image = [[UIImage imageNamed:picArray[i]]  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.selectedImage = [[UIImage imageNamed:highArray[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        item.title = titleArray[i];
        
        [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor grayColor],NSForegroundColorAttributeName,[UIFont fontWithName:@"Helvetica"size:11.0*boringScale],NSFontAttributeName,nil]forState:UIControlStateNormal];
        
        //字体大小，颜色（被选中时）
        [item setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor],NSForegroundColorAttributeName,[UIFont fontWithName:@"Helvetica"size:12.0*boringScale],NSFontAttributeName,nil]forState:UIControlStateSelected];
        
    }
    
}

//#pragma UINavigationDelegate
//- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
//    //计算导航栏控制器子控制器个数
//    int count = (int)navigationController.viewControllers.count;
//    if (count == 2) {
//        self.tabBar.hidden = YES;
//    }else if(count == 1) {
//        self.tabBar.hidden = NO;
//    }
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
